<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        *{
            padding: 0;
            margin: 0;
            list-style: none;
        }
        #div1{
            width: 100px;
            background: #ccc;
            border: 1px solid red;
            position: absolute;
            display:none;
        }
    </style>
    <script>
        //屏蔽默认系统右键菜单
        //自定义右键菜单
        document.oncontextmenu=function(ev){
            var oEvent=ev||event;
            var oDiv=document.getElementById('div1');
            oDiv.style.display='block';

            //控制div在鼠标点击的地方 出现， 而不是定死在一个地方
            oDiv.style.left=oEvent.clientX+'px';
            oDiv.style.top=oEvent.clientY+'px';
            return false;
        }
        document.onclick=function(){
            var oDiv=document.getElementById('div1');
            
            oDiv.style.display='none';
        }
    </script>
</head>
<body>
    <div id="div1">
        <ul>
            <li>aaa</li>
            <li>bbb</li>
            <li>ccc</li>
            <li>ddd</li>
        </ul>
    </div>
</body>
</html>